package org.nf.web.servlet.param;

import org.nf.web.servlet.MethodArgumentResolver;
import org.nf.web.servlet.ServletApi;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import java.lang.reflect.Parameter;

/**
 * @author wangliang
 * @date 2023/4/8
 * 负责解析HttpSession参数
 */
public class HttpSessionMethodArgumentResolver implements MethodArgumentResolver {

    @Override
    public boolean supports(Parameter parameter) {
        return HttpSession.class.isAssignableFrom(parameter.getType());
    }

    @Override
    public Object resolve(Parameter parameter, ServletApi servletApi) {
        HttpServletRequest request = servletApi.request();
        return request.getSession();
    }
}
